<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/3/18
 * Time: 10:54
 */

namespace app\controller;


use app\domain\gasStation;
use rap\web\Request;

class GasstationController
{

    public function  getGasStationList (Request $request) {

        if ($request->method() == "POST") {
            $lat = $request->param('lat');
            $lon = $request->param('lon');
            $page = $request->param('page');

            $field = "id, station_name, address, lat, lon, price_92, price_95";
            $data = gasStation::getGasStation($lon, $lat,$where = [], $field);

            if ($data) return CommonController::success("获取数据成功", $data);
            elseif($data = false) return CommonController::false(404, "暂无数据", []);
            else return CommonController::false(500, "服务器正在开小差，请稍后重试", []);
        }
    }

    public function getGasStationNear (Request $request) {

        if ($request->method() == "POST") {
            $lat = $request->param('lat');
            $lon = $request->param('lon');
            $page = $request->param('page');

            $list = gasStation::getGasStationList($page,$lat, $lon);

            if ($list) return CommonController::success("获取数据成功", $list);
            elseif($data = false) return CommonController::false(404, "暂无数据", []);
            else return CommonController::false(500, "服务器正在开小差，请稍后重试", []);
        }
    }
}